<?php
class LZ_Comment
{
	var $id = 'comment_id';
	var $table = 'comment';
	
	function LZ_Comment()
	{
		$this->table = LZ_MYSQL_PREFIX.$this->table;
	}
	
	function add( $data = array())
	{
		global $db;
		$sql = make_insert_sql($this->table,$data);
		return ($db->query($sql));
	}
	
	function delete($id)
	{
		global $db;
		$sql = "DELETE FROM $this->table WHERE $this->id = '$id';";
		return $db->query($sql);
	}
	
	function update($id,$data)
	{
		global $db;
		$sql = make_update_sql($this->table,$data, array($this->id => $id));
		return $db->query($sql);
	}
	
	function get_one($id)
	{
		global $db;
		$sql = "SELECT * FROM `{$this->table}` WHERE `{$this->id}` = '$id';";
		return $db->get_one($sql);	
	}
	
	function get_list($data=array())
	{
		global $db;
		
		if (!is_array($data))
			$data = array('item_id'=>$data);
		$_s = $data['select']?$data['select']:'*';
		$sql = "SELECT $_s FROM `{$this->table}` WHERE 1=1 ";
		if ($data['item_id']) $sql.=" AND `item_id` = '".$data['item_id']."' "; 
		$sql.= " ORDER BY ";
		$sql.= ($data['order'])?$data['order']:'`time`';
		$sql.= ($data['asc'])?' ASC':' DESC';
		if ($data['from'] && $data['total'])
		{
			$sql.=" LIMIT ".$data['from'].",".$data['total'];
		}
		else if ($data['total'])
		{
			$sql.=" LIMIT ".$data['total'];
		}
		$sql.= ';';
		return $db->get_all($sql);
	}

}
?>